<template>
  <div class="page-container">
    <el-header>
      <div style="box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);border-radius: 4px">
        <div style="height:150px;box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);border-radius: 4px;">
          <el-row>
            <el-col :span="24">
              <div class="grid-content bg-purple-light" style="text-align: left;">当前操作进度</div>
            </el-col>
            <el-col :span="24">
              <div class="grid-content">
                <el-steps align-center :space="200" :active="active" finish-status="success">
                  <el-step title="1.选择合同"></el-step>
                  <el-step title="2.选择商品"></el-step>
                  <el-step title="3.参数设置"></el-step>
                </el-steps>
                <el-button
                  style="margin-top: 12px;"
                  v-if="this.active==1||this.active==2||this.active==3"
                  @click="preStep"
                >上一步</el-button>
                <el-button
                  style="margin-top: 12px;"
                  v-if="this.active==0||this.active==1"
                  @click="nextStep"
                >下一步</el-button>
                <el-button style="margin-top: 12px;" v-if="this.active==2" @click="save">保存</el-button>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-header>
    <el-main>
      <div>
        <el-tabs>
          <el-tab-pane v-if="this.active==0" label="合同信息">
            <div>
              <el-table
                :data="this.filters.res.rows"
                border=""
                style="width: 100%"
                @selection-change="handleSelectionChange"
              >
                <el-table-column prop="checks" type="selection"></el-table-column>
                <el-table-column prop="name" label="合同名称" width="180"></el-table-column>
                <el-table-column
                  prop="busiType"
                  label="业务类型"
                  width="180"
                  :formatter="formatBusiType"
                ></el-table-column>
                <el-table-column prop="supplierCode" label="供应商编码" width="180"></el-table-column>
                <el-table-column prop="supplierName" label="供应商名称" width="180"></el-table-column>
                <el-table-column prop="merchantCode" label="商家编码" width="180"></el-table-column>
                <!-- <el-table-column prop="productBarNo" label="商品条码" width="180"></el-table-column> -->
                <el-table-column
                  prop="tradeCurrency"
                  label="交易币别"
                  width="180"
                  :formatter="formatTradeCurrency"
                ></el-table-column>
                <el-table-column prop="code" label="合同编码" width="180"></el-table-column>
              </el-table>
              <div class="block" style="text-align: right;">
                <el-pagination
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="this.pageRequest.pageNum"
                  :page-sizes="[10, 20, 30, 50]"
                  :page-size="100"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="this.filters.res.total"
                ></el-pagination>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane v-if="this.active==1" label="选择商品">
            <div>
              <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
                <el-form :inline="true" :model="queryFiteris" :size="size" ref="queryFiteris">
                  <el-form-item prop="storeName">
                    <el-input v-model="queryFiteris.storeName" placeholder="店铺名称"></el-input>
                  </el-form-item>
                  <el-row>
                    <el-form-item>
                      <kt-button
                        icon="fa fa-search"
                        :label="$t('action.search')"
                        type="primary"
                        @click="queryShopapi(null)"
                      />
                    </el-form-item>
                    <el-form-item>
                      <kt-button
                        icon="fa fa-refresh"
                        :label="$t('action.reset')"
                        type="primary"
                        @click="resetForm()"
                      />
                    </el-form-item>
                  </el-row>
                </el-form>
              </div>
              <el-table
                :data="this.shopFilters.res.rows"
                border=""
                style="width: 100%"
                @selection-change="handleSelectionChangeShop"
              >
                <el-table-column prop="checkss" type="selection"></el-table-column>
                <el-table-column prop="chineseName" label="商品名称" width="180"></el-table-column>
                <el-table-column prop="merchantName" label="商家名称" width="180"></el-table-column>
                <el-table-column prop="storeName" label="店铺名称" width="180"></el-table-column>
                <el-table-column prop="code" label="商品编码" width="180"></el-table-column>
                <!-- <el-table-column prop="productVolume" label="体积(cm^3)" width="180"></el-table-column>
                <el-table-column prop="shelfLifeDays" label="保质期天数" width="180"></el-table-column>
                <el-table-column prop="returnDays" label="包退天数" width="180"></el-table-column>-->

                <!-- <el-table-column prop="thirdProductCode" label="第三方商品编码" width="180"></el-table-column> -->
                <el-table-column prop="type" label="商品类型" width="180" :formatter="formatType"></el-table-column>
                <!-- <el-table-column prop="artNo" label="货号" width="180"></el-table-column> -->
                <!-- <el-table-column prop="freightTemplateId" label="运费模板id" width="180"></el-table-column> -->
                <!-- <el-table-column prop="status" label="审核状态" width="180"></el-table-column> -->
                <!-- <el-table-column prop="saleCalcUnitId" label="销售计量单位主键id" width="180"></el-table-column> -->
                <el-table-column
                  prop="canSale"
                  label="上下架状态"
                  width="180"
                  :formatter="formatCanSale"
                ></el-table-column>
                <!-- <el-table-column prop="dataType" label="商品数据类型" width="180"></el-table-column>
                <el-table-column prop="barCode" label="商品条形码" width="180"></el-table-column>-->
              </el-table>
              <div class="block" style="text-align: right;">
                <el-pagination
                  @size-change="handleSizeChangeProduct"
                  @current-change="handleCurrentChangeProduct"
                  :current-page="this.pageRequestProduct.start"
                  :page-sizes="[10, 20, 30, 50]"
                  :page-size="100"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="this.shopFilters.res.total"
                ></el-pagination>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane v-if="this.active==2" label="参数设置">
            <div>
              <el-table :data="this.paramsFilters.res.rows" border="" style="width: 100%">
                <el-table-column prop="checkss" type="selection"></el-table-column>
                <el-table-column prop="chineseName" label="商品名称" width="180"></el-table-column>
                <el-table-column prop="merchantName" label="商家名称" width="180"></el-table-column>
                <el-table-column prop="storeName" label="店铺名称" width="180"></el-table-column>
                <el-table-column prop="code" label="商品编码" width="180"></el-table-column>
                <el-table-column prop="purchaseNum" label="本次采数量" width="180">
                  <template slot-scope="scope">
                    <el-input
                      size="mini"
                      v-model="scope.row.purchaseNum"
                      @change="change(scope.$index,scope.row)"
                    ></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="type" label="商品类型" width="180" :formatter="formatType"></el-table-column>
                <el-table-column
                  prop="canSale"
                  label="上下架状态"
                  width="180"
                  :formatter="formatCanSale"
                ></el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
          <!-- <el-tab-pane label="操作日志">
            <div>
              <el-table :data="tableLog" border style="width: 100%">
                <el-table-column prop="storeCode" label="店铺编码"></el-table-column>
                <el-table-column prop="mpId" label="商家商品id"></el-table-column>
                <el-table-column prop="storeName" label="店铺名称"></el-table-column>
                <el-table-column prop="mpCode" label="商品编码"></el-table-column>
                <el-table-column prop="mpName" label="商品名称"></el-table-column>
                <el-table-column prop="mpMeasurementUnit" label="主计量单位"></el-table-column>
                <el-table-column prop="mpPurchaseUnitRate" label="转换率"></el-table-column>
                <el-table-column prop="currencyCode" label="交易币别"></el-table-column>
                <el-table-column prop="mpSpec" label="商品规格"></el-table-column>
                <el-table-column prop="num" label="数量"></el-table-column>
                <el-table-column prop="distributionChannel" label="运输方式"></el-table-column>
              </el-table>
            </div>
          </el-tab-pane>-->
        </el-tabs>
      </div>
      <!-- <div style="box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);border-radius: 4px;"> -->
      <!--工具栏-->
      <!-- <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
          <el-form :inline="true" :model="filters" :size="size" ref="filters">
            <el-form-item prop="merchantName">
              <el-input v-model="filters.merchantName" readonly placeholder="选择商家" @focus="queryMerchantList"></el-input>
            </el-form-item>
            <el-form-item prop="merchantId">
              <el-input style="display:none" v-model="filters.merchantId"  hidden placeholder="商家id"></el-input>
            </el-form-item>
            <el-form-item prop="supplierCode">
              <el-input v-model="filters.supplierCode" placeholder="供应商编码"></el-input>
            </el-form-item>
            <el-form-item prop="supplierName">
              <el-input v-model="filters.supplierName" placeholder="供应商名称"></el-input>
            </el-form-item>
            <el-form-item prop="contractCode">
              <el-input v-model="filters.contractCode" placeholder="合同编码"></el-input>
            </el-form-item>
            <el-row>
              <el-form-item>
                <kt-button
                  icon="fa fa-search"
                  :label="$t('action.search')"
                  type="primary"
                  @click="findPage(null)"
                />
              </el-form-item>
              <el-form-item>
                <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')"/>
              </el-form-item>
            </el-row>
          </el-form>
      </div>-->
      <!-- <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;"> -->
      <!-- <el-form :inline="true" :size="size">
            <el-form-item>
              <el-button-group>
                <el-tooltip content="刷新" placement="top">
                  <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
                </el-tooltip>
                <el-tooltip content="列显示" placement="top">
                  <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
                </el-tooltip>
              </el-button-group>
            </el-form-item>
      </el-form>-->
      <!--表格显示列界面-->
      <!-- <table-column-filter-dialog
            ref="tableColumnFilterDialog"
            :columns="columns"
            @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>-->
      <!-- </div> -->
      <!--表格内容栏-->
      <!-- <cy-table
          :height="350"
          :data="pageResult"
          :columns="filterColumns"
          :showOperation="false"
          :showEditOperation="false"
          :showDeleteOperation="false"
          :showBatchDelete="false"
          @findPage="findPage"
          @selectionChange="selectionChange"
          ref="CyTable"
      ></cy-table>-->
      <!-- </div> -->
    </el-main>
    <!--选择商家页面-->
    <el-dialog
      title="选择商家"
      width="40%"
      :visible.sync="editDialogVisible"
      :close-on-click-modal="false"
    >
      <el-form :model="dataFormMerchant" label-width="140px" ref="dataFormMerchant" :size="size">
        <el-row class="search-input">
          <el-form-item label="供应商编号：" prop="merchantCode">
            <el-input v-model="dataFormMerchant.merchantCode" auto-complete="off" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="供应商名称：" prop="merchantName">
            <el-input v-model="dataFormMerchant.merchantName" auto-complete="off" placeholder="请输入"></el-input>
          </el-form-item>
        </el-row>
        <el-row class="search-button">
          <el-button
            :size="size"
            type="primary"
            @click.native="a"
            :loading="editLoading"
          >{{$t('action.submit')}}</el-button>
          <el-button
            :size="size"
            type="primary"
            @click.native="resetForm('dataFormMerchant')"
          >{{$t('action.reset')}}</el-button>
        </el-row>
      </el-form>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="merchantCode" label="商家编码" width="150"></el-table-column>
        <el-table-column prop="merchantName" label="商家名称" width="150"></el-table-column>
        <el-table-column prop="merchantTypeName" label="商家类型"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="clickMerchant(scope.$index, scope.row)">选择此项</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import CyTable from "@/views/Core/CyTable";
import KtTable from "@/views/Core/KtTable";
import KtButton from "@/views/Core/KtButton";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
import { format } from "@/utils/datetime";
import utils from "@/assets/js/utils.js";

export default {
  name: "ContractProductPriceStep1",

  components: {
    CyTable,
    KtButton,
    TableColumnFilterDialog
  },

  data() {
    return {
      currentPage3: 1,
      currentPage4: 1,
      size: "small",
      multipleSelection: [],
      multipleSelectionShop: [],
      multipleSelectionParams: [],
      shopFilters: {
        res: {
          total: 0,
          code: "0000",
          rows: [{}]
        }
      },
      paramsFilters: {
        res: {
          total: 0,
          code: "0000",
          rows: [{}]
        }
      },
      dataFormRules: {
        purchaseNum: [
          { required: true, message: "请输入采购数量", trigger: "blur" }
        ]
      },
      filters: {
        merchantName: "",
        merchantId: "",
        supplierCode: "",
        supplierName: "",
        contractCode: "",
        res: {
          total: 0,
          code: "0000",
          rows: [
            //   {
            //   "id": 1911290007105037,
            //   "createTimeStr": null,
            //   "contractCode": "HT1911290007105036",
            //   "contractType": 2,
            //   "contractTypeText": "代销合同",
            //   "contractStatus": 2,
            //   "contractStatusText": "已审核",
            //   "supplierCode": "1911290006866570",
            //   "supplierName": "对账美元代销供应商",
            //   "currencyCode": "USD",
            //   "contractAmount": null,
            //   "effectiveTime": 1574870400000,
            //   "effectiveTimeStart": null,
            //   "effectiveTimeEnd": null,
            //   "expireTime": 1636473600000,
            //   "expireTimeStart": null,
            //   "expireTimeEnd": null,
            //   "auditTime": null,
            //   "auditTimeStart": null,
            //   "auditTimeEnd": null,
            //   "paymentPeriodId": 1909220000100060,
            //   "paymentPeriodName": "代销对账",
            //   "paymentPeriodType": 1,
            //   "paymentPeriodTypeText": null,
            //   "paymentPeriodDay": 0,
            //   "settleRuleName": null,
            //   "settlePeriodType": null,
            //   "settlePeriodTypeText": null,
            //   "settleExpireDay": null,
            //   "turnoverChannel": null,
            //   "isReturn": 1,
            //   "isReturnText": null,
            //   "remark": null,
            //   "isPause": 0,
            //   "isPauseText": "正常",
            //   "isValid": 1,
            //   "isValidText": "有效",
            //   "isChange": 0,
            //   "isChangeText": "正常合同",
            //   "oldContractId": null,
            //   "oldContractCode": null,
            //   "contractChangeCode": null,
            //   "contractChangeTime": null,
            //   "merchantId": 1909110000098882,
            //   "merchantCode": "001",
            //   "merchantName": "张小二服饰",
            //   "contractVersion": null,
            //   "isDeleted": 0,
            //   "versionNo": 0,
            //   "companyId": 276,
            //   "createUserid": 1909160000172983,
            //   "createUsername": "merchant",
            //   "createTime": 1575008759000,
            //   "updateUserid": null,
            //   "updateUsername": null,
            //   "updateTime": 1575285210000,
            //   "currentPage": null,
            //   "itemsPerPage": null,
            //   "performStatusText": "已审核",
            //   "receivePort": null,
            //   "tradeMethod": null,
            //   "contractCategoryDTOS": [],
            //   "contractContactDTO": null,
            //   "feeTypeName": null,
            //   "feeAmount": null,
            //   "deductionRate": null,
            //   "merchantProductId": null,
            //   "merchantStoreId": null,
            //   "merchantProductIds": null,
            //   "merchantIds": null,
            //   "storeIds": null,
            //   "categoryCodes": null,
            //   "notContractStatus": null,
            //   "categoryCode": null,
            //   "categoryName": null,
            //   "contractCodeList": null,
            //   "contractTypeList": null,
            //   "mpIdList": null,
            //   "paymentChannel": null,
            //   "paymentMethod": "3",
            //   "distributionChannel": null,
            //   "deliveryMode": null,
            //   "deliveryPort": null,
            //   "invoiceType": 2,
            //   "isForeignTrade": 0,
            //   "foreignTradeShow": null,
            //   "purchaseType": null,
            //   "changeUserType": null,
            //   "changeReason": null,
            //   "changeUserTypeStr": null,
            //   "contractProperty": "3",
            //   "contractPropertyText": "自采合同",
            //   "contractCategoryNames": null
            // }
          ]
        }
      },
      columns: [
        { prop: "name", label: "合同名称", minWidth: 120 },
        { prop: "supplierCode", label: "供应商编码", minWidth: 120 },
        { prop: "supplierName", label: "供应商名称", minWidth: 120 },
        { prop: "busiType", label: "业务类型", minWidth: 120 },
        { prop: "busiCode", label: "业务编码", minWidth: 120 },
        { prop: "code", label: "合同编码", minWidth: 120 },
        { prop: "merchantCode", label: "商家编码", minWidth: 120 },
        { prop: "merchantName", label: "商家名称", minWidth: 120 },
        { prop: "type", label: "合同属性", minWidth: 120 },
        { prop: "startTime", label: "生效开始时间", minWidth: 120 },
        { prop: "endTime", label: "生效结束时间", minWidth: 120 },
        { prop: "tradeCurrency", label: "交易币别", minWidth: 120 },
        { prop: "status", label: "状态", minWidth: 120 },
        { prop: "createTime", label: "制单时间", minWidth: 120 },
        { prop: "creator", label: "制单人", minWidth: 120 }
      ],

      tableData: [
        {
          currentPage: 0,
          itemsPerPage: 0,
          id: null,
          merchantId: 1910100000066478,
          merchantCode: "300001",
          merchantCodes: null,
          merchantName: "录屏商家02",
          merchantType: 11,
          merchantTypeName: "自营商家",
          isDefault: null,
          userId: null,
          status: null,
          merchantIds: null,
          isAvailable: null,
          isDeleted: null,
          versionNo: null,
          createUserid: null,
          createUsername: null,
          createUserip: null,
          createUsermac: null,
          createTime: null,
          createTimeDb: null,
          serverIp: null,
          updateUserid: null,
          updateUsername: null,
          updateUserip: null,
          updateUsermac: null,
          updateTime: null,
          updateTimeDb: null,
          clientVersionno: null,
          companyId: null,
          userName: null,
          startItem: 0
        },
        {
          currentPage: 0,
          itemsPerPage: 0,
          id: null,
          merchantId: 1910100000065618,
          merchantCode: "30001",
          merchantCodes: null,
          merchantName: "录屏商家01",
          merchantType: 11,
          merchantTypeName: "自营商家",
          isDefault: null,
          userId: null,
          status: null,
          merchantIds: null,
          isAvailable: null,
          isDeleted: null,
          versionNo: null,
          createUserid: null,
          createUsername: null,
          createUserip: null,
          createUsermac: null,
          createTime: null,
          createTimeDb: null,
          serverIp: null,
          updateUserid: null,
          updateUsername: null,
          updateUserip: null,
          updateUsermac: null,
          updateTime: null,
          updateTimeDb: null,
          clientVersionno: null,
          companyId: null,
          userName: null,
          startItem: 0
        },
        {
          currentPage: 0,
          itemsPerPage: 0,
          id: null,
          merchantId: 1910100000065171,
          merchantCode: "20001",
          merchantCodes: null,
          merchantName: "商家01",
          merchantType: 11,
          merchantTypeName: "自营商家",
          isDefault: null,
          userId: null,
          status: null,
          merchantIds: null,
          isAvailable: null,
          isDeleted: null,
          versionNo: null,
          createUserid: null,
          createUsername: null,
          createUserip: null,
          createUsermac: null,
          createTime: null,
          createTimeDb: null,
          serverIp: null,
          updateUserid: null,
          updateUsername: null,
          updateUserip: null,
          updateUsermac: null,
          updateTime: null,
          updateTimeDb: null,
          clientVersionno: null,
          companyId: null,
          userName: null,
          startItem: 0
        },
        {
          currentPage: 0,
          itemsPerPage: 0,
          id: null,
          merchantId: 1910100000063331,
          merchantCode: "009888",
          merchantCodes: null,
          merchantName: "测试商家shan古",
          merchantType: 11,
          merchantTypeName: "自营商家",
          isDefault: null,
          userId: null,
          status: null,
          merchantIds: null,
          isAvailable: null,
          isDeleted: null,
          versionNo: null,
          createUserid: null,
          createUsername: null,
          createUserip: null,
          createUsermac: null,
          createTime: null,
          createTimeDb: null,
          serverIp: null,
          updateUserid: null,
          updateUsername: null,
          updateUserip: null,
          updateUsermac: null,
          updateTime: null,
          updateTimeDb: null,
          clientVersionno: null,
          companyId: null,
          userName: null,
          startItem: 0
        },
        {
          currentPage: 0,
          itemsPerPage: 0,
          id: null,
          merchantId: 1910080000131175,
          merchantCode: "002",
          merchantCodes: null,
          merchantName: "育学园-测试",
          merchantType: 11,
          merchantTypeName: "自营商家",
          isDefault: null,
          userId: null,
          status: null,
          merchantIds: null,
          isAvailable: null,
          isDeleted: null,
          versionNo: null,
          createUserid: null,
          createUsername: null,
          createUserip: null,
          createUsermac: null,
          createTime: null,
          createTimeDb: null,
          serverIp: null,
          updateUserid: null,
          updateUsername: null,
          updateUserip: null,
          updateUsermac: null,
          updateTime: null,
          updateTimeDb: null,
          clientVersionno: null,
          companyId: null,
          userName: null,
          startItem: 0
        },
        {
          currentPage: 0,
          itemsPerPage: 0,
          id: null,
          merchantId: 1909190000580354,
          merchantCode: "1901",
          merchantCodes: null,
          merchantName: "test001",
          merchantType: 11,
          merchantTypeName: "自营商家",
          isDefault: null,
          userId: null,
          status: null,
          merchantIds: null,
          isAvailable: null,
          isDeleted: null,
          versionNo: null,
          createUserid: null,
          createUsername: null,
          createUserip: null,
          createUsermac: null,
          createTime: null,
          createTimeDb: null,
          serverIp: null,
          updateUserid: null,
          updateUsername: null,
          updateUserip: null,
          updateUsermac: null,
          updateTime: null,
          updateTimeDb: null,
          clientVersionno: null,
          companyId: null,
          userName: null,
          startItem: 0
        },
        {
          currentPage: 0,
          itemsPerPage: 0,
          id: null,
          merchantId: 1909190000034117,
          merchantCode: "yxy03",
          merchantCodes: null,
          merchantName: "育学园-商城",
          merchantType: 11,
          merchantTypeName: "自营商家",
          isDefault: null,
          userId: null,
          status: null,
          merchantIds: null,
          isAvailable: null,
          isDeleted: null,
          versionNo: null,
          createUserid: null,
          createUsername: null,
          createUserip: null,
          createUsermac: null,
          createTime: null,
          createTimeDb: null,
          serverIp: null,
          updateUserid: null,
          updateUsername: null,
          updateUserip: null,
          updateUsermac: null,
          updateTime: null,
          updateTimeDb: null,
          clientVersionno: null,
          companyId: null,
          userName: null,
          startItem: 0
        },
        {
          currentPage: 0,
          itemsPerPage: 0,
          id: null,
          merchantId: 1909190000034086,
          merchantCode: "yxy02",
          merchantCodes: null,
          merchantName: "育学园-教育",
          merchantType: 11,
          merchantTypeName: "自营商家",
          isDefault: null,
          userId: null,
          status: null,
          merchantIds: null,
          isAvailable: null,
          isDeleted: null,
          versionNo: null,
          createUserid: null,
          createUsername: null,
          createUserip: null,
          createUsermac: null,
          createTime: null,
          createTimeDb: null,
          serverIp: null,
          updateUserid: null,
          updateUsername: null,
          updateUserip: null,
          updateUsermac: null,
          updateTime: null,
          updateTimeDb: null,
          clientVersionno: null,
          companyId: null,
          userName: null,
          startItem: 0
        },
        {
          currentPage: 0,
          itemsPerPage: 0,
          id: null,
          merchantId: 1909190000034080,
          merchantCode: "yxy01",
          merchantCodes: null,
          merchantName: "育学园-会员",
          merchantType: 12,
          merchantTypeName: "入驻商家",
          isDefault: null,
          userId: null,
          status: null,
          merchantIds: null,
          isAvailable: null,
          isDeleted: null,
          versionNo: null,
          createUserid: null,
          createUsername: null,
          createUserip: null,
          createUsermac: null,
          createTime: null,
          createTimeDb: null,
          serverIp: null,
          updateUserid: null,
          updateUsername: null,
          updateUserip: null,
          updateUsermac: null,
          updateTime: null,
          updateTimeDb: null,
          clientVersionno: null,
          companyId: null,
          userName: null,
          startItem: 0
        },
        {
          currentPage: 0,
          itemsPerPage: 0,
          id: null,
          merchantId: 1909110000098882,
          merchantCode: "001",
          merchantCodes: null,
          merchantName: "张小二服饰",
          merchantType: 11,
          merchantTypeName: "自营商家",
          isDefault: null,
          userId: null,
          status: null,
          merchantIds: null,
          isAvailable: null,
          isDeleted: null,
          versionNo: null,
          createUserid: null,
          createUsername: null,
          createUserip: null,
          createUsermac: null,
          createTime: null,
          createTimeDb: null,
          serverIp: null,
          updateUserid: null,
          updateUsername: null,
          updateUserip: null,
          updateUsermac: null,
          updateTime: null,
          updateTimeDb: null,
          clientVersionno: null,
          companyId: null,
          userName: null,
          startItem: 0
        }
      ],
      queryFiteris: {},
      shopContract: [],
      filterColumns: [],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageRequestProduct: { start: 1, limit: 10 },
      pageResult: {},

      editLoading: false,
      active: 0,
      editDialogVisible: false, // 新增编辑界面是否显示
      dataFormMerchant: {
        merchantCode: "",
        merchantName: ""
      }
    };
  },

  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageRequest.pageSize = val;
      this.findPage(null);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageRequest.pageNum = val;
      this.findPage(null);
    },
    handleSizeChangeProduct(val) {
      console.log(`每页 ${val} 条`);
      this.pageRequestProduct.limit = val;
      this.queryShopapi();
    },
    handleCurrentChangeProduct(val) {
      console.log(`当前页: ${val}`);
      this.pageRequestProduct.start = val;
      this.queryShopapi();
    },
    queryMerchantList: function() {
      this.editDialogVisible = true;
    },

    // 获取分页数据
    findPage: function(data) {
      // this.$refs.CyTable.findPageStaticState(this.filters);
      let this_ = this;
      if (this_.queryFiteris === undefined || this_.queryFiteris === null) {
        this_.queryFiteris = {};
      }
      // this_.dataForm.pageNum = data === null || data === undefined ? this.pageRequest.pageNum : data;
      this_.queryFiteris.pageSize = this.pageRequest.pageSize;
      this_.queryFiteris.pageNum = this.pageRequest.pageNum;
      this.utils.request.findPurchaseContractPage(this_.queryFiteris, function(
        res
      ) {
        if (res.code === "0000") {
          this_.filters.res.rows = res.data.rows;
          this_.filters.res.total = res.data.total;
          console.log(res.data);
          console.log(this_.tableData);
          // this_.totalSize = Number(res.data.total);
          this_.$refs.CyTable.findPageStaticState(this_.filters);
        } else {
          this_.tableData = [];
          this_.totalSize = 0;
        }
      });
    },
    queryShopapi() {
      let this_ = this;
      if (this_.queryFiteris === undefined || this_.queryFiteris === null) {
        this_.queryFiteris = {};
      }
      // this_.dataForm.pageNum = data === null || data === undefined ? this.pageRequest.pageNum : data;
      this_.queryFiteris.limit = this.pageRequestProduct.limit;
      this_.queryFiteris.start = this.pageRequestProduct.start;
      this.utils.request.queryShopApi(this_.queryFiteris, function(res) {
        if (res.code === "0000") {
          this_.shopFilters.res.rows = res.data.rows;
          this_.shopFilters.res.total = res.data.total;
          console.log(res.data);
          console.log(this_.tableData);
          // this_.totalSize = Number(res.data.total);
          this_.$refs.CyTable.findPageStaticState(this_.shopFilters);
        } else {
          this_.tableData = [];
          this_.totalSize = 0;
        }
      });
    },
    formatBusiType(row, column, cellValue, index) {
      if (cellValue == 1) {
        return "采购合同";
      } else if (cellValue == 2) {
        return "代销合同";
      } else if (cellValue == 3) {
        return "经销合同";
      }
    },
    formatTradeCurrency(row, column, cellValue, index) {
      if (cellValue == "CNY") {
        return "人名币";
      } else if (cellValue == "USD") {
        return "美元";
      }
    },
    formatCanSale(row, column, cellValue, index) {
      if (cellValue == 0) {
        return "上架";
      } else if (cellValue == 1) {
        return "下架";
      }
    },
    formatType(row, column, cellValue, index) {
      if (cellValue == 1) {
        return "常规商品";
      } else if (cellValue == 2) {
        return "卡卷";
      } else if (cellValue == 3) {
        return "海购";
      } else if (cellValue == 4) {
        return "赠品";
      }
    },
    // 处理表格列过滤显示
    displayFilterColumnsDialog: function() {
      this.$refs.tableColumnFilterDialog.setDialogVisible(true);
    },

    change(index, e) {
      let this_ = this;
      this.shopContract.push(e);
      console.log(e);
      console.log(this.shopContract);
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(JSON.stringify(this.multipleSelection));
    },
    handleSelectionChangeShop(val) {
      this.multipleSelectionShop = val;
      console.log(JSON.stringify(this.multipleSelectionShop));
    },
    handleSelectionChangeParams(val) {
      this.multipleSelectionParams = val;
      console.log(JSON.stringify(this.multipleSelectionParams));
    },

    // 处理表格列过滤显示
    handleFilterColumns: function(data) {
      this.filterColumns = data.filterColumns;
      this.$refs.tableColumnFilterDialog.setDialogVisible(false);
    },

    // 处理表格列过滤显示
    initColumns: function() {
      let temp = [];

      $.each(this.columns, function(key, val) {
        temp.push(val);
      });
      this.filterColumns = temp;
    },
    preStep: function() {
      var this_ = this;
      if (this_.active == 1) {
        this_.multipleSelection = [];
      }
      if (this_.active == 2) {
        this_.multipleSelectionShop = [];
      }
      this_.pageRequest.pageNum = 1;
      this_.pageRequest.pageSize = 10;
      this_.pageRequestProduct.start = 1;
      this_.pageRequestProduct.limit = 10;
      var i = this_.active;
      this_.active = i - 1;
      this_.findPage(null);
    },
    nextStep: function() {
      var this_ = this;
      if (this_.active == 0) {
        if (this_.multipleSelection.length > 1 || this_.multipleSelection < 1) {
          this_.$message({ message: "请选择一条数据", type: "error" });
          return;
        }
      }
      if (this_.active == 1) {
        if (this_.multipleSelectionShop.length < 1) {
          this_.$message({ message: "请选择一条或多条数据", type: "error" });
          return;
        } else {
          this_.paramsFilters.res.rows = this_.multipleSelectionShop;
        }
      }
      if (this_.active == 1) {
      }
      this_.pageRequest.pageNum = 1;
      this_.pageRequest.pageSize = 10;
      this_.pageRequestProduct.start = 1;
      this_.pageRequestProduct.limit = 10;
      this_.queryShopapi();
      var i = this_.active;
      this_.active = i + 1;
    },
    save: function() {
      var this_ = this;
      console.log(this_.paramsFilters);
      let datass = this_.paramsFilters.res.rows;
      for (var i = 0; i < datass.length; i++) {
        if (
          datass[i].purchaseNum == 0 ||
          datass[i].purchaseNum == undefined ||
          datass[i].purchaseNum == null ||
          datass[i].purchaseNum == ""
        ) {
          this_.$message({ message: "请输入采购数量", type: "error" });
          return;
        }
      }
      //保存合同商品数据
      // for(var i=0;i<datass.length;i++){
      //   datass[i].contractCode=this_.multipleSelection[0].code;
      //   datass[i].productName=datass[i].chineseName;
      //   datass[i].deleteFlag=0;
      //   datass[i].id=null;
      //   this_.utils.request.addPurchaseContractProductRel(datass[i], function (res) {
      //   });
      // }
      datass.forEach(element => {
        element.contractCode = this_.multipleSelection[0].code;
        element.productName = element.chineseName;
        element.deleteFlag = 0;
        element.id = null;
        this_.utils.request.addPurchaseContractProductRel(element, function(
          res
        ) {});
      });
      // this.utils.request.deletePurchaseContract({id:this_.multipleSelection[0].id},this.deleteInfoBack)
      this_.$message({ message: "操作成功", type: "success" });
      this_.pageRequest.pageNum = 1;
      this_.pageRequest.pageSize = 10;
      this_.pageRequestProduct.start = 1;
      this_.pageRequestProduct.limit = 10;
      this_.multipleSelection = [];
      this_.multipleSelectionShop = [];
      this_.active = 0;

      // var flag=0;
      // let params=[];
      // params=this_.shopContract;
      // if(params.length<1||params.length<this_.multipleSelectionShop.length){
      //   this_.$message({message: "请输入采购数量", type: "error"});
      //   return;
      // }else{
      //   for(var i=0;i<params.length;i++){
      //     if(params[i].purchaseNum==0||params[i].purchaseNum==null||params[i].purchaseNum==''||params[i].purchaseNum==undefined){
      //       // this_.$message({message: "请输入采购数量", type: "error"});
      //       flag=1;
      //       break;
      //     }
      //   }
      // }
      // if(flag==0){
      //   for(var i=0;i<datass.length;i++){
      //     datass[i].contractCode=this_.multipleSelection[0].code;
      //     datass[i].productName=datass[i].chineseName;
      //     datass[i].deleteFlag=0;
      //     this_.utils.request.addPurchaseContractProductRel(datass[i], function (res) {
      //     });
      //   }
      //     // this.utils.request.deletePurchaseContract({id:this_.multipleSelection[0].id},this.deleteInfoBack)
      //    this_.$message({message: "操作成功", type: "success"});
      //   this_.multipleSelection=[];
      //   this_.multipleSelectionShop=[];
      //   this_.active =0;
      // }else{
      //   this_.$message({message: "请输入采购数量", type: "error"});
      //   return;
      // }
    },
    //删除callback
    deleteInfoBack(data) {
      if (data.code == "0000") {
        this.$message({ message: "操作成功", type: "success" });
      } else {
        this.$message({ message: "操作失败, ", type: "error" });
      }
      this.findPage();
    },
    resetForm(formName) {
      console.log("666666");
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
        this.filters.start_time = "";
        this.filters.end_time = "";
      } else {
        this.queryFiteris.storeName = null;
        this.queryShopapi(null);
      }
    },

    clickMerchant: function(index, row) {
      let this_ = this;
      console.log("tttttt");
      console.log(index, row);
      this_.filters.merchantName = row.merchantName;
      this_.filters.merchantId = row.merchantId;
      this_.editDialogVisible = false;
    },

    //选择框
    selectionChange: function(params) {
      this.checked = params.selections;
    },
    // 批量删除
    handleDelete: function(data) {
      if (data != null && data.params != null && data.params.length > 0) {
        let ids = data.params.map(item => item.id).toString();

        var params = {};
        params.t = "changeProduct";
        params.ids = ids;
        var this_ = this;
        this.utils.request.deleteUserInfo(params, function(res) {
          if (res.code == "0000") {
            this_.$message({ message: "操作成功", type: "success" });
            this_.findPage(null);
          } else {
            this_.$message({ message: "操作失败, " + res.msg, type: "error" });
          }
        });
      }
    }
  },
  mounted() {
    this.findPage();
    this.initColumns();
  }
};
</script>

<style scoped lang='scss'>
/deep/ .form .el-input__inner {
  width: 200px !important;
}
</style>
